﻿using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Net;
using System.Windows;
using Microsoft.Practices.Prism.MefExtensions;
using SNSpirit.Application;

namespace SNSpirit
{
    public class Bootstrapper : Application.Bootstrapper
    {
        protected override AggregateCatalog CreateAggregateCatalog()
        {
            // For test now
            AggregateCatalog catalog = new AggregateCatalog(new ComposablePartCatalog[]{
                new AssemblyCatalog(typeof(App).Assembly),  // app
                new AssemblyCatalog(typeof(SNSpirit.InteropServices.Utility).Assembly), // core
                new AssemblyCatalog(typeof(Debug.DebugModule).Assembly) // debug
            });

            return catalog;
        }

        protected override CompositionContainer CreateContainer()
        {
            CompositionContainer container = new CompositionContainer(this.AggregateCatalog);
            container.ComposeExportedValue(container);
            return container;
        }

        protected override DependencyObject CreateShell()
        {
            // return main shell
            var mainWindow = new MainWindow();
            var viewModel = new MainWindowViewModel();
            mainWindow.DataContext = viewModel;
            return mainWindow;
        }

        protected override void InitializeShell()
        {
            // show main window
            (this.Shell as MainWindow).Show();
            // other shell
            // check configuration
            if (ApplicationRuntime.Current.RuntimeConfiguration.IsEnableDebugConsole)
            {
                DebugConsole debugConsole = new DebugConsole();
                var viewModel = new DebugConsoleViewModel();
                debugConsole.DataContext = viewModel;
                // show it
                debugConsole.Show();
            }
        }
    }
}